/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author Nam
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "ProductDetail.findAll", query = "SELECT p FROM ProductDetail p"),
    @NamedQuery(name = "ProductDetail.findByVal", query = "SELECT p FROM ProductDetail p WHERE p.val = :val"),
    @NamedQuery(name = "ProductDetail.findByInfotypeId", query = "SELECT p FROM ProductDetail p WHERE p.infoType.id = :infoTypeId"),
    @NamedQuery(name = "ProductDetail.findByProduct", query = "SELECT p FROM ProductDetail p WHERE p.product = :product")})
@IdClass(value = ProductDetailId.class)
public class ProductDetail implements ICommonEntity, Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @ManyToOne
    private Product product;

    @Id
    @ManyToOne
    private InfoType infoType;

    @Column(length = 600)
    private String val;

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public InfoType getInfoType() {
        return infoType;
    }

    public void setInfoType(InfoType infoType) {
        this.infoType = infoType;
    }

    public String getVal() {
        return val;
    }

    public void setValue(String val) {
        this.val = val;
    }

    public Object getId() {
        if (product == null || infoType == null || product.getId() == null || infoType.getId() == null) {
            return null;
        }
        return new ProductDetailId(infoType.getId(), product.getId());
    }

    @Override
    public String toString() {
        return "ProductDetail{" + "product=" + product + ", infoType=" + infoType + ", val=" + val + '}';
    }
}
